package ru.dc.gui.swing.util;

import javax.swing.*;
import java.awt.*;
import java.util.ResourceBundle;

/**
 * <pre>
 * User: Penkov Vladimir
 * Date: 02.11.2010
 * Time: 18:35:10
 * </pre>
 */
public class LocalizedListCellRenderer extends DefaultListCellRenderer {
    private ResourceBundle rb;

    public LocalizedListCellRenderer() {
        rb = ResourceBundle.getBundle("locale/messages");
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        String str = value.toString();
        if (rb.containsKey(str)) {
            label.setText(rb.getString(str));
        }

        return label;

    }
}
